/**
 * Copyright (c) 2018, wuxie All rights reserved.
 * qq:16349023,mail:16349023@qq.com
 * 未经许可禁止任何人通过任何渠道使用、修改源代码.
 * 项目名称 : wxcloud
 *
 * @version V1.0
 */
package cn.xo68.boot.auth.core;

import cn.xo68.boot.auth.core.configuration.CookieConfiguration;
import cn.xo68.boot.auth.core.configuration.ShireCacheConfiguration;
import cn.xo68.boot.auth.core.web.ShiroMethodArgumentResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 *  认证 核心 自动配置
 * @author wuxie
 * @date 2018/8/5 16:18
 *
 */
@Configuration
@Import({CookieConfiguration.class, ShireCacheConfiguration.class})
public class AuthCoreAutoConfiguration {



    @Bean
    public WebMvcConfigurer shiroMethodArgConfigurer() {

        return new WebMvcConfigurer() {
            @Override
            public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
                resolvers.add(new ShiroMethodArgumentResolver());
            }
            @Override
            public void addCorsMappings(CorsRegistry registry) {
                // 设置了可以被跨域访问的路径和可以被哪些主机跨域访问
                registry.addMapping("/**")
                        .allowedOrigins("*")
                        .allowedHeaders("Origin",
                                "X-Requested-With",
                                "Content-Type",
                                "Accept",
                                "Access-Control-Allow-Headers",
                                "Access-Control-Request-Method",
                                "Host",
                                "Authorization",
                                "x-access-token",
                                "Access-Control-Allow-Origin",
                                "x-author")
                        .allowedMethods("*")
                        .allowCredentials(true);
            }
        };
    }

}

